package hy;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ali")
public class PayCtrl {
    @Autowired
    AlipayClient alipayClient;
    @RequestMapping("/pay")
    public String alipy(AlipayBean b){
        System.out.println(b);
        //设置请求参数
        AlipayTradePagePayRequest request=new AlipayTradePagePayRequest();
        //request.setReturnUrl();//同步通知
        //request.setNotifyUrl("http://hy.com/nofify/ali");
        request.setBizContent(JSON.toJSONString(b));

        String rs=null;
        try{
            rs=alipayClient.pageExecute(request).getBody();
            System.out.println(rs);
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }
}
